<template>
	<div class="port-page">
		<!-- 模糊搜索条件 -->
		<div class="but1">
			<router-link to="/home">
				<el-button type="warning" size="small" style='margin-right: 5px;' class="add btn" icon="el-icon-menu">首页</el-button>
			</router-link>
			<el-button type="success" size="small" style='margin-right: 5px;' class="add btn" @click='componentsShow("bujiao",ysbjidmc)' icon="el-icon-edit">新生报名</el-button>

			<el-button type="success" v-if="this.$route.query.iid" class="btn" size="small" icon="el-icon-edit" @click="componentsShow('add2')">添加转班学生</el-button>

		</div>
		<div class="search">
			<div class="search-item">
				<el-select v-model="ysbjid" clearable @change="search" class="code-search" placeholder="请选择预设班级" style="width: 130px;">
					<el-option :label="v.mc" :value="v.id+''" v-for="v in ysbjList"></el-option>
				</el-select>
			</div>
			<div class="search-item">
				<el-input placeholder="请输入中文名检索" class="code-search" v-model="zwm" @keyup.enter.native="search" icon="search"></el-input>
			</div>
			<el-button type="primary" size="small" style="border-radius:13px;" class="add btn" :loading="searchLoading" @click="search" icon="el-icon-search"></el-button>
		</div>
		<!--<el-button type="danger" class="add btn" v-if="false" :disabled="multipleDeleteDisabled" icon="delete" @click="componentsShow('multipleDelete','')">批量删除</el-button>-->
		<!-- 数据表格展示区域 -->
		<el-table :data="dataList" :cell-style="styletest" stripe border size="small" align="center" class="admin-table" @select="checkSelect" @select-all="checkall">
			<!--<el-table-column type="selection" width="55"></el-table-column>-->
			<div slot='empty'>
				<img src="../../../assets/img/empty.png" style="width:40px;vertical-align: middle;">
				<span style="vertical-align: middle;">暂时还没有内容哦!</span>
			</div>
			<el-table-column :prop="v.prop" :label="v.label" v-for="(v,index) in portTitleList" align="center" show-overflow-tooltip v-if="v.hide != 0" :formatter="v.formatter" :align="v.align || 'center'" :fixed="v.fixed" :class-name="v.columnStyle" :width="v.width" :min-width="v.minWidth" :header-align="v.headerAlign || 'center'">
				<!--<template scope="scope">
                    <div slot="reference" >
                        <div v-if="scope.column.property == 'wjje'" @click="componentsShow('info',scope)">
                            <span style="vertical-align:middle;">{{ scope.row[scope.column.property] }}</span>
                        </div>
                        <span style="vertical-align:middle;" v-else>{{ scope.row[scope.column.property] }}</span>
                    </div>
                </template>-->
				<template scope="scope">
					<div slot="reference">
						<div v-if="scope.column.property == 'zwm'" @click="componentsShow('info',scope)">
							<img :src="scope.row.xb == '男' ? $store.state.sexImg.boy : $store.state.sexImg.girl" style="width:20px;vertical-align:middle; float: left;" v-if="scope.column.property == 'zwm'">
							<span style="vertical-align:middle;">{{ scope.row[scope.column.property] }}</span>
						</div>
						<span style="vertical-align:middle;" v-else>{{ scope.row[scope.column.property] }}</span>
					</div>
					<!--<div slot="reference" >
                     	<div v-if="scope.column.property == 'wjje'">
                            <span style="color:red;"></span>
                       </div>
                     </div>-->
				</template>
			</el-table-column>

			<el-table-column label="操作" width="170px" align="center" :fixed="'right'">
				<template scope="scope">
					<!-- v-if="scope.row.qx == 'Y'"-->
					<el-button size="mini" type="warning" @click="componentsShow('bujiao',scope)" >缴费</el-button>
					<el-dropdown>
	                     <el-button type="primary" size="mini"> 更多<i class="el-icon-arrow-down el-icon--right"></i></el-button>
						 <el-dropdown-menu slot="dropdown">
						    <el-dropdown-item><el-button size="mini" type="warning" @click="componentsShow('info',scope)">编辑</el-button></el-dropdown-item>
						    <el-dropdown-item><el-button size="mini" type="danger" @click="componentsShow('change',scope)" >转班</el-button></el-dropdown-item>
						    <el-dropdown-item><el-button size="mini"  type="danger"  @click="componentsShow('yc',scope)">删除</el-button></el-dropdown-item>
						 </el-dropdown-menu>
					 </el-dropdown>
					<!-- <el-button size="small" type="text" @click="componentsShow('bujiao',scope)">补交</el-button> -->

					<!--<router-link  :to="{path:'/cost/payjl',query: {iid:scope.row.zwm,id:scope.row.id}}">
						<el-button size="small"  v-if="scope.row.iszd=='Y' && scope.row.wjje>0" type="warning" @click="componentsShow('jiaofei',scope)">补交</el-button>
					</router-link>-->

					<!--<router-link :to="{path:'/cost/payjl',query: {iid:scope.row.zwm,id:scope.row.id}}">
						<el-button size="small" v-if="scope.row.wjje>0" type="warning" @click="componentsShow('jiaofei',scope)">补交</el-button>
					</router-link>-->

					<!--<el-button size="small" v-if="scope.row.iszd=='N'" disabled type="primary" @click="componentsShow('jiaofei',scope)">账单</el-button>

					<router-link :to="{path:'/cost/payjl',query: {iid:scope.row.zwm,id:scope.row.id}}">
						<el-button size="small" v-if="scope.row.iszd=='Y' && scope.row.wjje<=0" type="primary" @click="componentsShow('jiaofei',scope)">账单</el-button>
					</router-link>-->
					<!--<el-button size="small" type="danger" @click="componentsShow('yc',scope)">移除</el-button>-->

				</template>
			</el-table-column>
		</el-table>
		<!-- 分页查询区域 -->
		<el-pagination
			@size-change="handleSizeChange"
			@current-change="handleCurrentChange"
			:current-page.sync="pageindex"
			:page-sizes="pagesizes"
			:page-size="pagesize"
			:layout="layout"
			:total="total"
			class="class-page">
		</el-pagination>
		<!-- 各个组件显示区域 -->
		<!-- 动画加载 -->
		<BujiaoComponent v-if="portComponents.bujiao.toggle" @close="componentsHide" :params="portComponents.bujiao.params" ></BujiaoComponent>
		
		<LoadingComponent v-show="isLoading"></LoadingComponent>
		<!-- 添加组件 -->
 		<ChangeComponent v-if="portComponents.change.toggle"  @close="componentsHide"  :params="portComponents.change.params" ></ChangeComponent>
		<AddtComponent v-if="portComponents.add2.toggle" @close="componentsHide" :params="portComponents.add2.params"></AddtComponent>
		<!-- 编辑组件 -->
		<EditComponent v-if="portComponents.edit.toggle" @close="componentsHide" :params="portComponents.edit.params"></EditComponent>
		<!-- info组件 -->
		<infoComponent v-if="portComponents.info.toggle" @close="componentsHide" :params="portComponents.info.params"></infoComponent>
		<!-- 缴费组件 -->
		<!--<BjComponent v-if="portComponents.bujiao.toggle" @close="componentsHide" :params="portComponents.bujiao.params"></BjComponent>-->
		<!-- 缴费组件 -->
		<JFComponent v-if="portComponents.jiaofei.toggle" @close="componentsHide" :params="portComponents.jiaofei.params"></JFComponent>

		<YcComponent v-if="portComponents.yc.toggle" @close="componentsHide" :params="portComponents.yc.params" ></YcComponent>

		<!-- 单独删除组件 -->
		<DeleteComponent v-if="portComponents.singleDelete.toggle" @close="componentsHide" :data="portComponents.singleDelete.data"></DeleteComponent>
		<!-- 批量删除组件 -->
		<DeleteComponent v-if="portComponents.multipleDelete.toggle" @close="componentsHide" :data="portComponents.multipleDelete.data"></DeleteComponent>
		<!-- 子路由显示区域 -->
		<router-view class="port-view"></router-view>
	</div>
</template>
<script>
	import qs from 'qs'
	import { mapState } from 'vuex'
	import BujiaoComponent from './add'
	import LoadingComponent from 'components/loading'
	import AddtComponent from './add0'
	import EditComponent from './edit'
	import YcComponent from './yc'
	import ChangeComponent from '../../educa/classManage/student/change'
	import InfoComponent from '../../educa/classManage/student/info'
	//	import BjComponent from './bujiao'
	import DeleteComponent from './del'
	// import JFComponent from '../pay/list'
	
	export default {
		props: ['params'],
		components: {
			LoadingComponent,
			DeleteComponent,
			BujiaoComponent,
			EditComponent,
			InfoComponent,
			AddtComponent,
			ChangeComponent,
			YcComponent
		},
		data() {
			return {
				zwm: '', // 关键字
				visqy: '',
				vbjid: '',
				multipleDelNum: '', //获取批量选择的数据
				dataList: [], //表格数据
				comboxlist: [], //下拉框 动态的
				ysbjid: '', //下拉框name 动态的
				ysbjList: [],
				ysbjidmc:'',
				/*动画加载*/
				isLoading: true, //动画加载
				searchLoading: false, //搜索按钮触发按钮动画
				/*分页属性设置*/

				layout: 'total, sizes, prev, pager, next, jumper', //组件布局
				pageindex: this.$store.state.pageindex, //当前分页页码
				pagesizes: this.$store.state.pagesizes, //显示个数的选择器选项
				pagesize: this.$store.state.pagesize, //每页显示条目数
				total: 0, //总条数

				/*组件区域*/
				portComponents: {
					/* 单行删除  */
					singleDelete: {
						type: 'singleDelete',
						toggle: false,
						params: '',
						data: {
							index: '',
							type: 'single',
							title: '此操作将删除该记录?, 是否继续?'
						}
					},
					/* 批量删除 */
					multipleDelete: {
						type: 'multipleDelete',
						toggle: false,
						params: '',
						data: {
							index: '',
							type: 'multiple',
							title: '此操作将删除您选中的记录?, 是否继续?'
						}
					},
					/* 添加 */
					bujiao: {
						type: 'bujiao',
						toggle: false,
						params: '',
						data: {}
					},
					/* 添加 */
					add2: {
						type: 'add2',
						toggle: false,
						params: '',
						data: {}
					},
					/* 编辑 */
					edit: {
						type: 'edit',
						toggle: false,
						params: '',
						data: {}
					},
					/* info */
					info: {
						type: 'info',
						toggle: false,
						params: '',
						data: {}
					},
					/* bujiao*/
					jiaofei: {
						type: 'jiaofei',
						toggle: false,
						params: '',
						data: {}
					},
					yc: {
						type: 'yc',
						toggle: false,
						params: '',
						data: {}
					},
					change: {
                        type: 'change',
                        toggle: false,
                        params: '',
                        data: {}
                    },
				},
				/*
				    prop :  接口参数名
				    label : 接口中文名
				    hide : 是否隐藏这一列
				    align : 这一列对齐顺序 ： left,right,center
				    headerAlign : 这一列表头对齐方式 ： left,right,center
				*/
				portTitleList: [{
						prop: 'zwm',
						label: '中文名',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center'
					},

					{
						prop: 'ysbjmc',
						label: '预设班级',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column, cellValue) {
							cellValue = 'aaaaaa';
						}
					},
					{
						prop: 'dh',
						label: '电话',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column, cellValue) {
							cellValue = 'aaaaaa';
							return cellValue;
						}
					},
					
					{
						prop: 'fmdh',
						label: '父母电话',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column, cellValue) {
						}
					},
					{
						prop: 'bmsj',
						label: '报名时间',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column, cellValue) {
						}
					},
					
					

					{
						prop: 'wjje',
						label: '还需交',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column, cellValue) {
							cellValue = 'aaaaaa';
							return cellValue;
						}
					},
					{
						prop: 'yuer',
						label: '账户余额',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						columnStyle: 'wztempstyle',
						formatter: function(row, column, cellValue) {
							cellValue = 'aaaaaa';
							return cellValue;
						}
					},
					

				]
			}
		},
		created() {
			if(this.$route.query.iid) {
				this.ysbjid = this.$route.query.iid + ''
				this.ysbjmc = this.$route.query.mc + ''
				this.ysbjidmc={
					ysbjid:this.ysbjid,bjmc:this.ysbjmc,zt:1
				}
			}
			if(this.$route.query.bjmc){
              this.bjmc = this.$route.query.bjmc
            }
			//加载页面时调用
			this.$store.dispatch('changeTitle','预设班新生报名缴费'); //修改title
			this.$store.dispatch('changeRouterIndex', '/cost/xsbaoming'); //修改路由
			
			this.search(); //分页获取默认数据
			this.ysbj(); //加载下拉列表
			this.isLoading = true; //动画开始
			if(this.$route.query.iid) {
				if(this.$route.query.frompage == 'xsadd') {
					this.componentsShow("bujiao");
				}
			}
		},
		mounted() {
			//加载完成之后event
			this.isLoading = false; //动画结束
		},
		methods: {

			styletest(boj) {
				if(boj.columnIndex == 3) {
					if(this.dataList[boj.rowIndex].wjje > 0) {
						return 'color:red'
					}
				}
				return '';
			},
			tableCellControl(scope) { //表格单元格控制CSS样式
				// console.log(scope)
				if(scope.column.property == "zt") {
					return {
						color: "green",
					}
				} else {
					return {
						color: "red",
					}
				}
			},
			search() {
				//查询搜索触发事件
				var logininfo = JSON.parse(localStorage.logininfo);
				var params3 = qs.stringify({
					ysbjid: this.ysbjid,
					yhid: logininfo.id,
					xxid: logininfo.xxid,
					pageindex: this.pageindex,
					pagesize: this.pagesize
				});
				this.searchLoading = true;
				this.axios.post(this.$store.state.api + 'xs/getysbjxss1', params3)
					.then(res => {
						console.log(res,'dddddddd')
						let data = res.data.data;
						let list = data.listdate;
						this.total = data.totalCnt;
						this.dataList = list;
						this.searchLoading = false;
					}).catch(res => {
						this.searchLoading = false;
					})
			},
			ysbj() {
				var logininfo = JSON.parse(localStorage.logininfo);
				var params3 = qs.stringify({
					yhid: logininfo.id,
					xxid: logininfo.xxid
				});
				this.axios.post(this.$store.state.api + 'ysbj/bjsylist', params3)
					.then(res => {
						this.ysbjList = res.data.data;
					}).catch(res => {
					})
			},
			tableCellControl(scope) {
				//表格单元格控制CSS样式
				/*if (scope.row.id == 112 && scope.column.property == "iname") {
				    return {
				        color:"red",
				    }
				}else{
				    return {
				        color:"green",
				    }
				}*/
			},
			handleSizeChange(val) { //每页显示条数触发事件
				this.pagesize = val;
				this.pageindex = 1;
				this.search();
			},
			handleCurrentChange(val) { //分页触发事件
				this.search();
			},
			checkSelect(selection, row) { //点击单选select触发事件
				let strID = [];
				selection.forEach(function(v, i) {
					strID.push(v.id)
				})
				this.multipleDelNum = strID.join(",");
			},
			checkall(selection) { //点击全选select触发事件
				let strID = [];
				selection.forEach(function(v, i) {
					strID.push(v.id)
				})
				this.multipleDelNum = strID.join(",");
			},
			/* 组件的弹框  */
			componentsShow(type, data) { //显示组件
				for(let i in this.portComponents) {
					if(type == this.portComponents[i].type) {
						this.portComponents[i].toggle = true;
						this.portComponents[i].params = data;
						if(this.portComponents[i].data.type == 'single') {
							this.portComponents[i].data.index = data.row.id
						} else if(this.portComponents[i].data.type == 'multiple') {
							this.portComponents[i].data.index = this.multipleDelNum;
						} else {
							return;
						}
						return;
					}
				}
			},
			componentsHide(setting) { //关闭组件
				this.search();
				for(let i in this.portComponents) {
					if(setting.type == this.portComponents[i].type) {
						this.portComponents[i].toggle = false;
						if(setting.type == "add") {
							if(setting.nextop == 'openjf') {
								var xsid = setting.xsid;
								var xszwm = setting.xszwm;
								var scope = {
									row: {
										id: xsid,
										zwm: xszwm
									}
								};
								this.componentsShow('jiaofei', scope)
							}
						}
						if(!setting.cancel) {
							this.search();
						}
						return;
					}
				}
			}
		},
		computed: {
			...mapState([
				'api' //域名
			]),
			multipleDeleteDisabled() {
				if(this.multipleDelNum) {
					return false;
				} else {
					return true
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	.wztempstyle {
		color: red;
	}
	
	.admin-table {
		/deep/ .el-table__fixed-right {
			height: 100% !important; //设置高优先，以覆盖内联样式
		}
	}
	
	.port-page {
		font-size: 12px;
		.btn {
			height: 30px;
			padding: 0 10px;
			margin-top: 8px;
			margin-left: 0;
		}
		.but1 {
			width: 30%;
			height: 50px;
			float: left;
			line-height: 50px;
		}
		.search {
			width: 70%;
			height: 50px;
			line-height: 50px;
			float: right;
			text-align: right;
		}
		.code-search {
			 max-width: 130px;
            min-width: 100px;
            text-align: center;
            height: 50px;
            /*line-height: 50px;*/
            font-size: 12px;
		}
		.class-page {
			text-align: left;
			margin-top: 10px;
		}
		.search-item {
			display: inline-block;
		}
	}
</style>